<?php
/**
 * @page simple_content_module Simple Content Module
 * 
 * This module creates simple content box based on your select. You can select which content to show:
 * Listings/Reviews/Users and set the criteria/conditions for them. 
 * 
 * @image html simple_content_module.jpg
 * 
 */
class SimpleContentBoxModule extends GigaModule
{
	var $name = 'Simple Content Box';
	
	var $configuration = array(
		'model' => array(
			'type' => 'select',
			'empty' => '-Select-',
			'group' => 'add',
			'label' => 'Content Type',
			'class'=>"scope_model_select",
			'options' => array('Listing'=>'Listings', 'Review'=>'Reviews', 'User' => 'Users', 'ReviewComment'=>'ReviewComments'),
			'triggers' => array('onChange' => array('update' => 'scope', 'from_model' => 'Content')),
			'validate'=> VALID_NOT_EMPTY	
		),
		
		'scope' => array(
			'type' => 'select',
			'empty' => '-Select-',
			'group' => 'add',
			'validate'=> VALID_NOT_EMPTY
		),
		'limit'=>array(
			'type'=>"text",
			'label'=>"Number of records to be shown",
			'group'=>"add",
			'default'=>5,
			
		),
		'view_type'=>array(
			'label'=>'Display Style',
			'type'=>'radio',
			'options'=>array(
				'table_view'=>'Tableview',
				'blog_view'=>'Blogview'
				),
			'default'=>'table_view',
			'group'=>"add",
		),
		'custom_view' => array(
			'label'=>'Custom View File',
			'type'=>'text',
			'group'=>"add",
		)
	);
	function __construct()
	{
		$this->configuration['scope']['label'] = __("Filter")." &nbsp;&nbsp;&nbsp;(<a href=\"javascript:void(0);\" class=\"addNewScope\" onclick=\"addScope(this)\">".__("Define new")."</a>)";
	}
	function render($params)
	{
		$viewObj = ClassRegistry::getObject('view');
		$limit = $this->configuration['limit']['default'];
		$entity_plural = low(Inflector::pluralize($params['model']));
		extract($params);
		$params = compact('model','limit','scope','view_type');
		$records = cri('ContentScope')->getContent($params,$viewObj->params);
		if(!is_array($records) || empty($records))
		{
			$return = false; 
		}else{
			$viewFile = $entity_plural;
			if(isset($custom_view) && strlen($custom_view))
			{
				$viewFile = $custom_view;
			}
			$return = $viewObj->element($viewFile, array($entity_plural => $records,'view_type'=>$view_type,'isModuleRender'=>true));
		}
		return $return;
	}

}
?>
